define(["dijit/form/Button", "dojo/dom", "dojo/json", "dojo/request", "dojo/_base/window",
	"dojo/_base/declare", "dojo/parser", "dijit/_WidgetBase", "dijit/_TemplatedMixin", "dijit/registry", "dijit/layout/ContentPane", "dojo/ready"],
	function(Button, dom, JSON, request, win, declare, parser, _WidgetBase, _TemplatedMixin, registry, ContentPane, ready){
		
		return declare("my.Widget", [_WidgetBase, _TemplatedMixin], {
			templateString:
                "<div>" + 
				"<div data-dojo-type='dijit/layout/ContentPane' style='height: 100%; width: 100%;' data-dojo-attach-point='main'>" +
					"<div data-dojo-type='dijit/layout/ContentPane' region='top' style='height: 40%;'></div>" +
					"<div data-dojo-type='dijit/layout/ContentPane' region='leading' style='width:40%;'></div>" +
					"<div data-dojo-type='dijit/layout/ContentPane' region='trailing' style='width:40%'></div>" +
					"<div data-dojo-type='dijit/layout/ContentPane' region='center' style='height: 100%; width:100%;'>" +
						"<button data-dojo-type='dijit/form/Button' data-dojo-attach-event='onclick: createWidget'>Create Widget</button>" +
					"</div>" +
                "</div>" +
				"</div>",
			
			//title: "",
			//location: 0,
				
			update: function(){
				request.post("widgets", {
					data: JSON.stringify({opType: "getWidgets", value: {title: title, location: location}}),
					handleAs: "json"}).then(function(data){
						chart(data[view], data[variables], data[columns]);
					});
			},
				
			createWidget: function() {
				request.post("widgets", {
					data: JSON.stringify({opType: "widgetid", value: {location: location, title: title}}),
					handleAs: "json"}).then(function (data) {
						window.location = "/createWidget?widgetid=" + data;
					});
			}
		});
		
		ready(function() {
			parser.parse();
		});
	});
